﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

using DevExpress.XtraGrid.Views.Layout;
using DevExpress.XtraGrid.Views.Layout.ViewInfo;

using Utility;

namespace hpm
{
    public partial class frmDangKyKham : DevExpress.XtraEditors.XtraForm
    {
        public frmDangKyKham()
        {
            InitializeComponent();
        }

        DataTable dtbObj = new DataTable();
        clsPhongKham objPhongKham = new clsPhongKham();
        DataRow dr;
        int ifectRow = 0;
        bool isSet = false;


        private void frmDangKyKham_Load(object sender, EventArgs e)
        {
            dtbObj = objPhongKham.GetAllPhongKham();
            grdDsPhongKham.DataSource = dtbObj;

            btneMaBenhNhan.Focus();

            lblPhongKham.Text = lvDanhSachPhong.GetFocusedRowCellValue("TenPhongKham").ToString();
            lblMaPhong.Text = lvDanhSachPhong.GetFocusedRowCellValue("MaPhongKham").ToString();
        }

        private void layoutView1_CustomDrawCardCaption(object sender, DevExpress.XtraGrid.Views.Layout.Events.LayoutViewCustomDrawCardCaptionEventArgs e)
        {
            /*
            if (!isSet)
            {
                if (ifectRow < dtbObj.Rows.Count)
                    dr = dtbObj.Rows[ifectRow];
                e.CardCaption = dr["TenPhongKham"].ToString();
                ifectRow++;

                isSet = true;
            }
             */
            e.CardCaption = "Phòng";
        }

        private void btnCauHinh_Click(object sender, EventArgs e)
        {
            try
            {
                
                


            }
            catch
            {
                MessageBox.Show("Vui lòng chọn 1 bệnh nhân trong danh sách.", "Thông báo");
                return;
            }
        }

        private void lvDanhSachPhong_Click(object sender, EventArgs e)
        {
            lblPhongKham.Text = lvDanhSachPhong.GetFocusedRowCellValue("TenPhongKham").ToString();
            lblMaPhong.Text = lvDanhSachPhong.GetFocusedRowCellValue("MaPhongKham").ToString();
            //MessageBox.Show(lvDanhSachPhong.GetFocusedRowCellValue("TenPhongKham").ToString());
        }

        private void btneMaBenhNhan_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            MessageBox.Show("A");
        }

        private void btneMaBenhNhan_KeyUp(object sender, KeyEventArgs e)
        {
            Validate_DangKy();
        }

        private void Validate_DangKy()
        {
            clsBenhNhan objBenhNhan = new clsBenhNhan();
            if (objBenhNhan.CheckExist(btneMaBenhNhan.Text))
            {
                objBenhNhan.MaBenhNhan = btneMaBenhNhan.Text;
                objBenhNhan = objBenhNhan.GetBenhNhanById();

                lblThongTinBenhNhan.Text = objBenhNhan.HoTen + ", " + objBenhNhan.NgaySinh + ", " + objBenhNhan.DiaChi;
            }
            else
            {
                lblThongTinBenhNhan.Text = "";
            }
        }

        private void btnDangKy_Click(object sender, EventArgs e)
        {
            if (btneMaBenhNhan.Text.Trim() == "")
            {
                MessageBox.Show("Nhập mã bệnh nhân");
                return;
            }
            else
            {
                clsBenhNhan objBenhNhan = new clsBenhNhan();
                if (!objBenhNhan.CheckExist(btneMaBenhNhan.Text))
                {
                    MessageBox.Show("Mã bệnh nhân không tồn tại.");
                    return;
                }
                clsDangKyKham objDangKyKham = new clsDangKyKham();
                objDangKyKham.MaBenhNhan = btnDangKy.Text;
                objDangKyKham.MaPhongKham = lblMaPhong.Text;
                objDangKyKham.NgayKham = HpmUtility.strNgayHienTai;
                objDangKyKham.TrangThai = "tiep_nhan";
                objDangKyKham.LuuDangKy();
            }
        }

   

     
    }
}